import request from '@/utils/request'

// 查询销售出库单列表
export function listOutbound(query) {
  return request({
    url: '/ck/outbound/findOutbound',
    method: 'post',
    params: query
  })
}

/**
 * 删除销售出库单
 * @param {number} sales_id - 出库单ID
 * @param {string} update_by - 更新人
 * @returns {Promise}
 */
export function deleteOutbound(sales_id, update_by) {
  return request({
    url: `/ck/outbound/updateSales_delete/${sales_id}/${update_by}`,
    method: 'get'
  });
}

/**
 * 批量删除销售出库单
 * @param {Array<number>} ids - 出库单ID列表
 * @param {string} updateBy - 更新人
 * @returns {Promise}
 */
export function deleteOutboundBatch(ids, updateBy) {
  return request({
    url: `/ck/outbound/deleteBatch/${updateBy}`,
    method: 'post',
    data: ids
  });
}

/**
 * 提交销售出库单
 * @param {number} id - 出库单ID
 * @returns {Promise}
 */
export function submitOutbound(id) {
  return request({
    url: '/ck/outbound/submit/' + id,
    method: 'put'
  })
}

// 销售出库操作（将状态改为已出库）
export function warehouseOutbound(sales_id,update_by) {
  return request({
    url: '/ck/outbound/warehouseOutbound/' + sales_id + '/' + update_by,
    method: 'get'
  })
}

// 获取销售出库单详情
export function getOutbound(query) {
  return request({
    url: '/ck/outbound/selectSalesOrderDetail',
    method: 'post',
    params: query
  })
}

// 新增销售出库单
export function addOutbound(data) {
  return request({
    url: '/ck/outbound/addOutbound',
    method: 'post',
    data: data
  })
}

// 修改销售出库单
export function updateOutbound(data) {
  return request({
    url: '/ck/outbound',
    method: 'put',
    data: data
  })
}

// 查询已确定的销售订单
export function selectSalesOrder(query) {
  return request({
    url: '/ck/outbound/selectSalesOrder',
    method: 'post',
    params: query
  })
}

// 查询销售订单下的商品详情
export function selectSalesOrderDetail(query) {
  return request({
    url: '/ck/outbound/selectSalesOrderDetail',
    method: 'post',
    params: query
  })
}

// 获取出库单商品详情(带分页)
export function getOutboundItems(query) {
  return request({
    url: '/ck/outbound/selectSalesLine',
    method: 'post',
    params: query
  })
}

// 添加修改销售出库单状态的API函数
export function updateOutboundStatus(salesId, status) {
  return request({
    url: `/ck/outbound/ckProductSalesStatus/${salesId}/${status}`,
    method: 'get'
  })
}

